<?php

namespace app\model\zs;

use think\Model;

/**
 * 奖励流水表
 */
class ZsRewardLog extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'reward_log';

    // 设置当前模型的数据库连接
    protected $connection = 'zs';

    // 自动写入时间的类型
    protected $autoWriteTimestamp = 'datetime';

    // 定义时间戳字段名
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';

    const TYPE_ACTIVITY_FORWARD = 1;
    const TYPE_ACTIVITY_VISIT = 2;
    const TYPE_ACTIVITY_DOWN = 3;
    const TYPE_ACTIVITY_NEWER = 4;
    // const TYPE_GRASS = 5;
    const TYPE_GRASS_NORMAL = 6;
    const TYPE_GRASS_PRIVILEGE_BAIYIN = 8;
    const TYPE_GRASS_PRIVILEGE_HUANGJIN = 9;
    const TYPE_GRASS_PRIVILEGE_ZUANSHI = 10;
    const TYPE_GRASS_PRIVILEGE_CHAOFAN = 11;
    const TYPE_GRASS_PRIVILEGE_WANGZHE = 1;

    /**
     * 奖励分类对应文本
     */
    public static function typeRels()
    {
        return [
            static::TYPE_ACTIVITY_FORWARD => '活动转发',
            static::TYPE_ACTIVITY_VISIT => '扫码访问',
            static::TYPE_ACTIVITY_DOWN => '海报下载',
            static::TYPE_ACTIVITY_NEWER => '海报扫码拉新',
            // static::TYPE_GRASS => '种草',
        ];
    }

    /**
     * 奖励分类对应文字（小程序端展示用）
     */
    public static function typeRelsMini()
    {
        return [
            static::TYPE_ACTIVITY_FORWARD => '商户活动转发',
            static::TYPE_ACTIVITY_VISIT => '商户活动扫码访问',
            static::TYPE_ACTIVITY_DOWN => '商户活动海报下载',
            static::TYPE_ACTIVITY_NEWER => '商户活动拉新',
            // static::TYPE_GRASS => '种草',
        ];
    }

    public function memberUser()
    {
        return $this->belongsTo(ZsMemberMeal::class, 'vipcode', 'vipcode');
    }

    public function memberNewer()
    {
        return $this->belongsTo(ZsMemberMeal::class, 'vipcode_newer', 'vipcode');
    }

    public function articleModel()
    {
        return $this->belongsTo(ZsMemberArticle::class, 'article_id', 'id');
    }

    public function businessActivityModel()
    {
        return $this->belongsTo(ZsBusinessActivity::class, 'business_activity_id', 'id');
    }
}
